package com.example.text31;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button button;
    EditText name, password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = findViewById(R.id.name);
        password = findViewById(R.id.password);
        button = findViewById(R.id.button);
        SharedPreferences sp = getSharedPreferences("three", MODE_PRIVATE);
        name.setText(sp.getString("name", ""));
        password.setText(sp.getString("password", ""));
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String names = name.getText().toString();
                String passwords = password.getText().toString();
                if("admin".equals(names)&&"123456".equals(passwords)){
                    Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
                    SharedPreferences sp = getSharedPreferences("three", MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("name", names);
                    edit.putString("password", passwords);
                    edit.commit();
                }else {
                    Toast.makeText(MainActivity.this, "登陆失败", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}